package com.itheima.health.utils.poi;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;

public class MainPoi {

    public static void main(String[] args) throws Exception {
       //  读取  excel
//          readExcel();

          createExcel();
    }

    private static void createExcel() throws Exception {

        //  生成 excel
           String  outputfilepath ="d:/heima.xlsx";

           XSSFWorkbook xssfWorkbook = new XSSFWorkbook();

        XSSFSheet sheet = xssfWorkbook.createSheet("传智健康");

        XSSFRow row = sheet.createRow(0);

        row.createCell(0).setCellValue("检查项");
        row.createCell(1).setCellValue("检查组");
        row.createCell(2).setCellValue("套餐");
        row.createCell(3).setCellValue("预约管理");


        XSSFRow row1 = sheet.createRow(1);

        row1.createCell(0).setCellValue("身高");
        row1.createCell(1).setCellValue("一般检查");
        row1.createCell(2).setCellValue("入职无忧");
        row1.createCell(3).setCellValue("嘿嘿嘿");
        //  response.getOutputStream()
        xssfWorkbook.write(new FileOutputStream(outputfilepath));


    }

    private static void readExcel() throws Exception {
        //  输入流    XSSF
        InputStream in  = new FileInputStream("D:\\上海-黑马程序员-课程资料\\项目-传智健康-V3.0\\传智健康Day05-预约管理 √\\资料\\hello.xlsx");
        XSSFWorkbook xssfWorkbook =new XSSFWorkbook(in);

        XSSFSheet sheet = xssfWorkbook.getSheetAt(0);

        for (Row row : sheet) {

            for (Cell cell : row) {

                System.out.print(cell.getStringCellValue()+"\t");
            }
            System.out.println();

        }

    }
}
